package com.kfm.web;

import com.kfm.util.Constant;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 欢迎页面
 * 判断用户是否登录
 */
@WebServlet("/welcome")
public class WelcomeServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Object user = req.getSession().getAttribute(Constant.LOGIN_USER_KEY);
        if (user == null) { // 没有登录, 重定向到登录页面
            System.out.println("未登录");
            resp.sendRedirect("/");
            return;
        }
        req.getRequestDispatcher("/WEB-INF/welcome.html").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
